{
 "cells": [
  {
   "cell_type": "code",
   "id": "4841a037",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-15T12:50:47.778357Z",
     "start_time": "2025-05-15T12:50:46.935653Z"
    }
   },
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import mean_squared_error\n",
    "from sklearn.neighbors import KNeighborsClassifier"
   ],
   "outputs": [],
   "execution_count": 1
  },
  {
   "cell_type": "code",
   "id": "90ef1d34",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-15T12:50:47.917531Z",
     "start_time": "2025-05-15T12:50:47.904001Z"
    }
   },
   "source": [
    "features = ['accommodates', 'bedrooms', 'bathrooms', 'beds', 'price', 'minimum_nights','maximum_nights', 'number_of_review']\n",
    "dc_listings = pd.read_csv('../CSV/listing.csv')\n",
    "dc_listings = dc_listings[features]\n",
    "norm_train_df, norm_test_df = train_test_split(dc_listings, test_size=0.2, random_state=42)"
   ],
   "outputs": [],
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-05-15T12:50:47.999591Z",
     "start_time": "2025-05-15T12:50:47.948620Z"
    }
   },
   "source": [
    "cols = ['accommodates' ,'bedrooms']\n",
    "knn = KNeighborsClassifier()\n",
    "knn.fit(norm_train_df[cols], norm_train_df['price'])\n",
    "two_features_predictions = knn.predict(norm_test_df[cols])"
   ],
   "outputs": [],
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "id": "6b3d8247",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-15T12:50:48.059941Z",
     "start_time": "2025-05-15T12:50:48.055669Z"
    }
   },
   "source": [
    "two_features_mse = mean_squared_error(norm_test_df['price'], two_features_predictions)\n",
    "two_features_rmse = two_features_mse ** (1/2)\n",
    "print(two_features_rmse)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "206.73389901029776\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "id": "c4c18c95",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-15T12:50:48.160486Z",
     "start_time": "2025-05-15T12:50:48.109913Z"
    }
   },
   "source": [
    "cols_three =  ['accommodates', 'bedrooms', 'bathrooms', 'beds']\n",
    "knn_4 = KNeighborsClassifier()\n",
    "knn_4.fit(norm_train_df[cols_three], norm_train_df['price'])\n",
    "four_features_predictions = knn_4.predict(norm_test_df[cols_three])\n",
    "four_features_mse = mean_squared_error(norm_test_df['price'], four_features_predictions)\n",
    "four_features_rmse = four_features_mse ** (1/2)\n",
    "print(four_features_rmse)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "211.09441371102173\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "id": "4b06afcb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-15T12:50:48.916451Z",
     "start_time": "2025-05-15T12:50:48.179072Z"
    }
   },
   "source": [
    "list = []\n",
    "for i in range(3, 21):\n",
    "    knn = KNeighborsClassifier(i)\n",
    "    knn.fit(norm_train_df[cols], norm_train_df['price'])\n",
    "    two_features_predictions = knn.predict(norm_test_df[cols])\n",
    "    two_features_mse = mean_squared_error(norm_test_df['price'], two_features_predictions)\n",
    "    two_features_rmse = two_features_mse ** (1/2)\n",
    "    list.append(two_features_rmse)\n",
    "print(list)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[187.75307321053364, 199.87754751347137, 206.73389901029776, 212.69763162762297, 212.39181834524607, 214.79656771000788, 218.0890586434817, 218.7216255883263, 222.34525517761784, 225.07539847793228, 227.67120810502146, 232.15431075041445, 229.55348614211897, 230.18775054289924, 227.0910103901077, 225.39651062072812, 228.5518934509185, 228.70595095012285]\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-15T12:50:48.934127Z",
     "start_time": "2025-05-15T12:50:48.931836Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "fe01cb728e3947b9",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
